Typy ==== byte - 8b short - 16b int - 32b long - 64b float - 32b double - 64b char - 16b, Unicode boolean - true, false Klasy: Character, Boolean, Integer, Float itp. z java.lang static int MAXVALUE static int MINVALUE konstruktor Integer(int i) konstruktor Integer(String s) int intValue() byte byteValue() itd... String toString() static int parseInt(String s) static Integer valueOf(int i) String, StringBuffer 123.4 - typu double 123.4f, 123.4F - typu float 123.4d, 123.4D - typu double 123l, 123L - typu long 'A' - typu char false - typu boolean Tablice, klasy i interfejsy są referencjami. final float PI = 3.14f; stała Wartość null. char[] helloArray = { 'h', 'e', 'l', 'l', 'o' }; String: (java.lang.String) int length() char charAt(int Index) String substring(int Begin, int End) StringBuffer: void append(char Ch) void insert(int Index, String s) String toString() Konwersja coś > łańcuch: int i = 123; String s = String.valueOf(i); Konwersja łańcuch > coś: String s = "123"; int i = Integer.valueOf(s); System.out.println(String s) Operatory ========= + - * / % ++ -- > >= < <= == != ! ^ ~ && || - ewaluacja jednego lub obydwu argumentów & | - ewaluacja zawsze obydwu argumentów >> << >>> += itd... is as instanceof Instrukcje ========== if (warunek) instrukcja1; [ else instrukcja2; ] switch (wyrażenie) { case Stała1: Instrukcja1; case Stała2: Instrukcja2; ... [ default: InstrukcjaX; ] } while (wyrażenie) instrukcja; do instrukcja while (wyrażenie); for (wyrażenie1; wyrażenie2; wyrażenie3) instrukcja; { instrukcja1; instrukcja2; ... } break; continue; Klasy ===== private, public, protected, package Klasa: abstract - cannot be instantiated final - cannot be inherited Pola: static final - nie może być zmieniane Metody: static abstract final - cannot be overriden native - impemented in other language synchronized public class Klasa1 extends KlasaBazowa implements InterfejsA { int Pole1 = 123; Klasa1() { // Konstruktor... } Klasa1(int X) { // Konstruktor z parametrem... } } Można przeciążać metody. this - mój obiekt super - odwołanie do klasy bazowej Klasa bazowa: java.lang.Object Object clone() interfejs Cloneable bool equals(?) ? hashCode(?) ? finalize(?) ? toString(?) ? getClass(?) notify, notifyAll, wait Nested Classes Inner Classes Wyjątki ======= Klasa Throwable, Exception try { ... } catch (ExceptionClass1 ExceptionObject) { ... } catch ... [ finally { ... } ] void Metoda1() throws Wyjatek1, Wyjatek2, ... { // Treść... } throw new Wyjatek1(...); Wątki ===== Sposób 1 -------- public class MojWatek1 extends Thread { public MojWatek1() { ... } public void run() { // kod osobnego wątku } } MojWatek1 watek1 = new MojWatek1(); watek1.start(); watek1.join(); Sposób 2 -------- public class MojWatek2 implements Runnable { private Thread myThread = null; public void start() { if (myThread == null) { myThread = new Thread(this, "Nazwa wątku"); myThread.start(); } } public void run() { ... } } void Thread.sleep(int Miliseconds) isAlive try { sleep((int)(Math.random() * 100)); } catch (InterruptedException e) { } Synchronizacja -------------- - Metody synchronized - instrukcja synchronized (Obiekt1) { ... } - wait(), notify(), notifyAll() wait() wait(long timeout) wait(long timeout, int nanos) Grupowanie ---------- ThreadGroup Grupa1 = new ThreadGroup("NazwaGrupy1"); Konstruktory Thread: public Thread(ThreadGroup group, Runnable runnable) public Thread(ThreadGroup group, String name) public Thread(ThreadGroup group, Runnable runnable, String name) Thread: getThreadGroup() getName() resume, stop, suspend ThreadGroup: int activeCount() activeGroupCount() Thread[] list() getMaxPriority, setMaxPriority getDaemon, setDaemon getName getParent, parentOf toString resume, stop, suspend Random ====== java.util.Random konstruktor Random() konstruktor Random(long Seed) boolean nextBoolean() double nextDouble() - 0 .. 1 float nextFloat() int nextInt() int nextInt(int n) - 0 .. n-1 ArrayList (1.4.2) ========= java.util.ArrayList konstruktor ArrayList() konstruktor ArrayList(int InitialCapacity) void add(int i, object o) boolean add(Object o) void clear() boolean contains(Object o) Object get(int i) int indexOf(Object e) boolean isEmpty() Object remove(int i) int size() Object set(int i, Object o)